package cn.alise.qdp.http.controller.api;

import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.alise.enums.EnumClass;
import cn.alise.exception.ServiceException;
import cn.alise.qdp.http.controller.common.BaseController;
import cn.alise.qdp.model.apiException.ApiException;
import cn.alise.qdp.model.common.JsonParam;
import cn.alise.qdp.model.common.ResultEntity;
import cn.alise.qdp.service.api.ApiService;
import cn.alise.qdp.service.apiException.ApiExceptionService;
import cn.alise.qdp.service.common.RedisService;
import cn.alise.util.JsonUtil;

/**
 * 接口控制器
 */
@Controller
@RequestMapping(value = "/api")
public class ApiController extends BaseController {

	private static final long serialVersionUID = 3071751434812887748L;
	
	@Resource(name = "apiService")
	private ApiService apiService;
	
	@Resource(name = "apiExceptionService")
	private ApiExceptionService apiExceptionService;
	
	@Resource(name = "redisService")
	private RedisService redisService;
	
    /**
	 * 登录
	 */
    @RequestMapping(value = "/login")
    public void login(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("登录");
		
		try {
			// 执行并返回
			ResultEntity result = this.apiService.login(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * APP版本比对
	 */
    @RequestMapping(value = "/checkAppVersion")
    public void checkAppVersion(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("APP版本比对");
		
		try {
			// 执行并返回
			ResultEntity result = this.apiService.checkAppVersion(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 登录注销
	 */
    @RequestMapping(value = "/logout")
    public void logout(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("登录注销");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMainMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.logout(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取个人信息
	 */
    @RequestMapping(value = "/getUserInfo")
    public void getUserInfo(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取个人信息");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
						
			// 从token获取mobile
	    	String mobile = this.redisService.getMainMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getUserInfo(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 编辑个人信息
	 */
    @RequestMapping(value = "/editUserInfo")
    public void editUserInfo(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("编辑个人信息");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMainMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.editUserInfo(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 密码修改
	 */
    @RequestMapping(value = "/editPwd")
    public void editPwd(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("密码修改");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMainMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.editPwd(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取类别图片库
	 */
    @RequestMapping(value = "/getCategoryImgs")
    public void getCategoryImgs(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取类别图片库");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getCategoryImgs(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 类别图片库新增图片
	 */
    @RequestMapping(value = "/uploadCategoryImg")
    public void uploadCategoryImg(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("类别图片库新增图片");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.uploadCategoryImg(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 类别图片库删除图片
	 */
    @RequestMapping(value = "/delCategoryImg")
    public void delCategoryImg(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("类别图片库删除图片");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.delCategoryImg(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取类别视频库
	 */
    @RequestMapping(value = "/getCategoryVideos")
    public void getCategoryVideos(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取类别视频库");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getCategoryVideos(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 类别视频库新增视频
	 */
    @RequestMapping(value = "/uploadCategoryVideo")
    public void uploadCategoryVideo(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("类别视频库新增视频");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.uploadCategoryVideo(jp, request);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 类别视频库删除视频
	 */
    @RequestMapping(value = "/delCategoryVideo")
    public void delCategoryVideo(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("类别视频库删除视频");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.delCategoryVideo(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取类别价格库
	 */
    @RequestMapping(value = "/getCategoryPrices")
    public void getCategoryPrices(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取类别价格库");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getCategoryPrices(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取价格详情
	 */
    @RequestMapping(value = "/getPriceDetail")
    public void getPriceDetail(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取价格详情");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getPriceDetail(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 类别价格库新增价格
	 */
    @RequestMapping(value = "/uploadCategoryPrice")
    public void uploadCategoryPrice(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("类别价格库新增价格");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.uploadCategoryPrice(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 类别价格库编辑价格
	 */
    @RequestMapping(value = "/editCategoryPrice")
    public void editCategoryPrice(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("类别价格库编辑价格");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.editCategoryPrice(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 类别价格库删除价格
	 */
    @RequestMapping(value = "/delCategoryPrice")
    public void delCategoryPrice(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("类别价格库删除价格");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.delCategoryPrice(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取其他图片库
	 */
    @RequestMapping(value = "/getOtherImgs")
    public void getOtherImgs(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取其他图片库");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getOtherImgs(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 其他图片库新增图片
	 */
    @RequestMapping(value = "/uploadOtherImg")
    public void uploadOtherImg(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("其他图片库新增图片");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.uploadOtherImg(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 其他图片库删除图片
	 */
    @RequestMapping(value = "/delOtherImg")
    public void delOtherImg(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("其他图片库删除图片");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.delOtherImg(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取清单
	 */
    @RequestMapping(value = "/getInventory")
    public void getInventory(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取清单");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getInventory(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 导入清单
	 */
    @RequestMapping(value = "/importInventory")
    public void importInventory(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("导入清单");
		
		try {
			
			if (!StringUtils.isEmpty(jp.getAccount())) {
				jp.setMobile(jp.getAccount());
			} else {
				// token判断
				this.redisService.judgeToken(request);
				
				// 从token获取mobile
		    	String mobile = this.redisService.getMobileByToken(request);
		    	jp.setMobile(mobile);
			}
			
			// 执行并返回
			ResultEntity result = this.apiService.importInventory(jp, request);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 获取子账号列表
	 */
    @RequestMapping(value = "/getAccountList")
    public void getAccountList(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("获取子账号列表");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMainMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.getAccountList(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 新增子账号
	 */
    @RequestMapping(value = "/addAccount")
    public void addAccount(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("新增子账号");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.addAccount(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 删除子账号
	 */
    @RequestMapping(value = "/delAccount")
    public void delAccount(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("删除子账号");
		
		try {
			// token判断
			this.redisService.judgeToken(request);
			
			// 从token获取mobile
	    	String mobile = this.redisService.getMobileByToken(request);
	    	jp.setMobile(mobile);
	    	
			// 执行并返回
			ResultEntity result = this.apiService.delAccount(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 账号注册(后台)
	 */
    @RequestMapping(value = "/register")
    public void register(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("账号注册(后台)");
		
		try {
			// 执行并返回
			ResultEntity result = this.apiService.register(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 更新会员过期时间(后台)
	 */
    @RequestMapping(value = "/updateExpireTime")
    public void updateExpireTime(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("更新会员过期时间(后台)");
		
		try {
			// 执行并返回
			ResultEntity result = this.apiService.updateExpireTime(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
    /**
	 * 同步139账号信息(后台)
	 */
    @RequestMapping(value = "/sync139Info")
    public void sync139Info(HttpServletRequest request, JsonParam jp, HttpServletResponse response) {

        //返回报文	
		String retJson = "";
		jp.setApiName("同步139账号信息(后台)");
		
		try {
			// 执行并返回
			ResultEntity result = this.apiService.sync139Info(jp);
			
			retJson = JsonUtil.toJSON(result);
			
		} catch (Exception e) {
			logger.error(e.getLocalizedMessage());
			retJson = this.getExceRetJson(e, false, jp);
		}
		
		getPrintWriter(response, retJson);
    }
    
	/**
	 * 获取返回的异常信息
	 * @param e
	 * @return
	 */
	private String getExceRetJson(Exception e, boolean saveFlow, JsonParam jp) {		
		int code = EnumClass.ResultCodeType.SYSERROR.getKey();
		String exceMsg = EnumClass.ResultCodeType.SYSERROR.getValue();
		if (e instanceof ServiceException) {
			ServiceException se = (ServiceException)e;
			code = se.getErrorCode();
			exceMsg = se.getMessage();
		} else {
			// 保存到接口异常记录表中
			ApiException api = new ApiException();
			api.setAccount(jp.getAccount());
			api.setApiName(jp.getApiName());
			if (!StringUtils.isEmpty(e.getMessage())) {
				api.setExceptionMsg(e.getMessage());
			} else if (!StringUtils.isEmpty(e.getLocalizedMessage())) {
				api.setExceptionMsg(e.getLocalizedMessage());
			} else {
				api.setExceptionMsg(e.toString());
			}
			api.setId(UUID.randomUUID().toString().replaceAll("-", ""));
			api.setServiceId(1L);
			this.apiExceptionService.save(api);
		}
		ResultEntity result = new ResultEntity(code, exceMsg);
		return JsonUtil.toJSON(result);
	}
}